package com.demo.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * @author zhangxiangnan
 * @date 2021/8/18  23:35
 */
@Aspect
@Component
public class TestAspect {

    @Around("@annotation(com.demo.aspect.annotation.LogAnnotation)")
    public Object aspectHandler(ProceedingJoinPoint pjp) throws Throwable {
        Object returnValue = null;
        try {
            System.out.println(">>>>> TestAspect before");

            // 获取方法的参数列表
            Object[] args = pjp.getArgs();
            // 调用业务层方法（切入点方法）
            returnValue = pjp.proceed(args);

            System.out.println("TestAspect afterReturning");

            return returnValue;
        } catch (Throwable t) {
            System.out.println("TestAspect afterThrowing");
            throw new RuntimeException(t);
        } finally {
            System.out.println("TestAspect after");
        }
    }
}
